#ifndef BODYPART_H
#define BODYPART_H

#include <iostream>
#include "btBulletDynamicsCommon.h"
#include "entity.h"
#include <vector>
#include "src/brainz/brainzarch.h"
#include "src/brainz/brainz.h"




using namespace std;

class Bodyowner;
class Food;
class CritterB;

class Bodypart : public Entity
{
	public:
		Bodypart(btDynamicsWorld* ownerWorld, Bodyowner* owner, const btVector3& dimensions, float weight, 
             btTransform& offset, btTransform& transform, BeColor color, entityType ownertype);
		virtual ~Bodypart();
    virtual void draw();
    virtual void draw(int colorsel);
    virtual void changeScale(float scale);
    virtual void preprocess(vector<CritterB*>& critters, vector<Entity*>& entities, unsigned long long frameCount) { return; };
    virtual void process(vector<CritterB*>& critters, vector<Entity*>& entities, unsigned long long frameCount) { return; };
    virtual void postprocess(vector<CritterB*>& critters, vector<Entity*>& entities, unsigned long long frameCount) { touchedby.clear(); return; };
    // Used by subclasses with special hitboxes to return proper physics object instead
    virtual btRigidBody* validateHitBody(btCollisionObject* co, btRigidBody* b) { return b; };
    // Used by subclasses to take notice of being touched
    vector<Bodypart*> touchedby;
    virtual void beTouchedBy(Bodypart* toucher) { touchedby.push_back(toucher); return; };
    virtual float beEaten(float amount);

    // Used to connect Neurons to this Bodypart.
    static  unsigned int registerInputs(BrainzArch* ba, unsigned int nextid);
    virtual unsigned int procInputs(Brainz& brain, unsigned int nindex);
    virtual unsigned int getNumberOfInputs();
    virtual unsigned int getNumberOfOutputs();
    static  unsigned int registerOutputs(BrainzArch* ba, unsigned int nextid);
    virtual unsigned int procOutputs(Brainz& brain, unsigned int nindex);


    // getOwner_* just here for temporary convenience while repositioning things in the code.
    Food* getOwner_food();
    CritterB* getOwner_critter();
    Bodyowner* getOwner() { return owner; };

		btRigidBody* 		body;
		btCollisionShape* 	shape;
    float weight;

		btDefaultMotionState*	myMotionState;

	public:
    Bodyowner* owner;
		btDynamicsWorld* 	m_ownerWorld;
    btScalar    position[16];
    btVector3   halfExtent;

};
#endif
